package com.bike.controller.information;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bike.controller.BaseController;
import com.bike.entity.HhWithdraw;
import com.bike.service.impl.HhWithdrawServiceImpl;
import com.bike.util.PageData;

 
@Controller
@RequestMapping(value="/hhWithdraw")
public class HhWithdrawController extends BaseController {
	
		@Autowired
		private HhWithdrawServiceImpl  hhWithdrawService;
	
		/**
		 * 跳转到列表页面
		 */
		@RequestMapping("toList")
		public String toList(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			model.addAttribute("pd", pd);
			return "/information/withdraw/hhWithdraw_list";
		}
		/**
		 * 列表查询(或根据条件)
		 */
		@RequestMapping("list")
		@ResponseBody
		public PageData list(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			return hhWithdrawService.selectHhWithdrawList(pd);
		}
		/**
		 * 列表查询(或根据条件)
		 */
		@RequestMapping("listAll")
		@ResponseBody
		public PageData listAll(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			return hhWithdrawService.selectHhWithdrawList(pd);
		}
		/**
		 * 跳转到编辑页面（新增和修改）
		 */
		@RequestMapping("toEdit")
		public String toEdit(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			if(pd.getLong("withdrawId")>0){
				model.addAttribute("pd", hhWithdrawService.selectByHhWithdrawId(pd.getLong("withdrawId")));
			} 
			return "/information/withdraw/hhWithdraw_edit";
		}
		/**
		 * 搜素
		 * @param request
		 * @param model
		 * @return
		 */
		@RequestMapping("toSearch")
		public String toSearch(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			model.addAttribute("pd", pd);
			return "/information/withdraw/hhWithdraw_search";
		}
		/**
		 * 新增和修改 
		 */
		@RequestMapping("save")
		@ResponseBody
		 public Map<String,Object> save(HttpServletRequest request,HhWithdraw hhWithdraw){
			try {
				PageData pd=PageData.getPageDataByPage(request);
				hhWithdrawService.saveOrUpdate(pd,hhWithdraw);
				return getSuccessMap();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return getErrorMap("失败");
		 }
		/**
		 * 提现完成
		 */
		@RequestMapping("updateWithdraw")
		@ResponseBody
		public Map<String,Object> updateWithdraw(HttpServletRequest request,HhWithdraw hhWithdraw){
			try {
				PageData pd=PageData.getPageDataByPage(request);
				hhWithdraw=hhWithdrawService.selectByHhWithdrawId(hhWithdraw.getWithdrawId());
				if(hhWithdraw.getStatus()==1){
					return getErrorMap("已经完成");
				}
				hhWithdrawService.updateWithdraw(pd,hhWithdraw);
				return getSuccessMap();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return getErrorMap("失败");
		}
		/**
		 * 删除
		 */
	 	@RequestMapping("delete")
		@ResponseBody
		 public Map<String,Object> delete(HttpServletRequest request){
			try {
				PageData pd=PageData.getPageDataByPage(request);
				if(pd.getLong("withdrawId")>0){
					hhWithdrawService.deleteHhWithdrawById(pd.getLong("withdrawId"));
					return getSuccessMap();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return getErrorMap("失败");
		}
	 	/**
	 	 * 提现中
	 	 */
	 	@RequestMapping("toListing")
	 	public  String  toListing(HttpServletRequest request,Model model){
	 		PageData pd=PageData.getPageDataByPage(request);
	 		pd.put("status", 0);
			model.addAttribute("pd", pd);
			return "/information/withdraw/hhWithdraw_list";
	 	}
}
